From d475a81961694bf19da2094d4a480bfe52dc2c43 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Tue, 15 Apr 2008 22:06:32 +0000 Subject: [PATCH] removed babl-classes.h removed and mostly folded into ... .. this file, * babl/Makefile.am: removed babl-classes.h * babl/babl-classes.h: removed and mostly folded into ... * babl/babl.h: .. this file, which has been reorganized to contain each separate class by itself. * babl/babl-internal.h: simplified code renamed BABL_CLASS_TEMPLATE to be just BABL_CLASS or BABL_CLASS_MINIMAL. * babl/babl-fish.c: (babl_fish): do not accept varargs, use use BABL_CLASS_MINIMAL. * babl/babl-component.c: * babl/babl-conversion.c: * babl/babl-extension.c: * babl/babl-format.c: * babl/babl-model.c: * babl/babl-type.c: use BABL_CLASS instead of BABL_CLASS_TEMPLATE * babl/babl-hash-table.h: * babl/babl-list.h: * babl/babl-db.h: changed include warning since babl-classes doesn't exist anymore. svn path=/trunk/; revision=308 --- ChangeLog | 24 ++ babl/Makefile.am | 4 +- babl/babl-classes.h | 293 ------------------------- babl/babl-component.c | 2 +- babl/babl-conversion.c | 2 +- babl/babl-db.h | 4 +- babl/babl-extension.c | 2 +- babl/babl-fish.c | 10 +- babl/babl-format.c | 2 +- babl/babl-hash-table.h | 4 +- babl/babl-internal.h | 111 +++++----- babl/babl-list.h | 6 +- babl/babl-model.c | 2 +- babl/babl-type.c | 2 +- babl/babl.h | 483 +++++++++++++++++++++++++++++++++++------ 15 files changed, 510 insertions(+), 441 deletions(-) delete mode 100644 babl/babl-classes.h diff --git a/ChangeLog b/ChangeLog index 6e9251e..1248a60 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2008-04-15 Øyvind Kolås + + * babl/Makefile.am: removed babl-classes.h + * babl/babl-classes.h: removed and mostly folded into ... + * babl/babl.h: .. this file, which has been reorganized to contain + each separate class by itself. + * babl/babl-internal.h: simplified code renamed BABL_CLASS_TEMPLATE to + be just BABL_CLASS or BABL_CLASS_MINIMAL. + + * babl/babl-fish.c: (babl_fish): do not accept varargs, use use + BABL_CLASS_MINIMAL. + + * babl/babl-component.c: + * babl/babl-conversion.c: + * babl/babl-extension.c: + * babl/babl-format.c: + * babl/babl-model.c: + * babl/babl-type.c: use BABL_CLASS instead of BABL_CLASS_TEMPLATE + + * babl/babl-hash-table.h: + * babl/babl-list.h: + * babl/babl-db.h: changed include warning since babl-classes doesn't + exist anymore. + 2008-04-15 Sven Neumann * extensions/util.h diff --git a/babl/Makefile.am b/babl/Makefile.am index b1038b8..2dcd4fe 100644 --- a/babl/Makefile.am +++ b/babl/Makefile.am @@ -32,7 +32,6 @@ c_sources = \ babl-hash-table.c h_sources = \ - babl-classes.h \ babl-db.h \ babl-ids.h \ babl-internal.h \ @@ -44,8 +43,7 @@ h_sources = \ library_includedir=$(includedir)/babl-$(BABL_API_VERSION)/babl library_include_HEADERS = \ - babl.h \ - babl-classes.h + babl.h INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/babl/base diff --git a/babl/babl-classes.h b/babl/babl-classes.h deleted file mode 100644 index 98b32b1..0000000 --- a/babl/babl-classes.h +++ /dev/null @@ -1,293 +0,0 @@ -/* babl - dynamically extendable universal pixel conversion library. - * Copyright (C) 2005, Øyvind Kolås. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, see - * . - */ - -#ifndef _BABL_CLASSES_H -#define _BABL_CLASSES_H - -/* Type and Format */ -typedef long (*BablFuncLinear) (char *src, - char *dst, - long n); - -/* Signature of functions registered for reference type - * conversions, - */ -typedef long (*BablFuncPlane) (char *src, - char *dst, - int src_pitch, - int dst_pitch, - long n); - -/* TypePlanar,ModelPlanar and FormatPlanar */ -typedef long (*BablFuncPlanar) (int src_bands, - char *src[], - int src_pitch[], - int dst_bands, - char *dst[], - int dst_pitch[], - long n); - -/* magic number used at the start of all babl objects, used to do - * differentiation in polymorphic functions. (as well as manual - * type check assertions). - */ -#define BABL_MAGIC 0xbAb100 - -typedef enum { - BABL_INSTANCE = BABL_MAGIC, - BABL_TYPE, - BABL_TYPE_INTEGER, - BABL_TYPE_FLOAT, - BABL_SAMPLING, - BABL_COMPONENT, - BABL_MODEL, - BABL_FORMAT, - - BABL_CONVERSION, - BABL_CONVERSION_LINEAR, - BABL_CONVERSION_PLANE, - BABL_CONVERSION_PLANAR, - - BABL_FISH, - BABL_FISH_REFERENCE, - BABL_FISH_SIMPLE, - BABL_FISH_PATH, - BABL_IMAGE, - - BABL_EXTENSION, - - BABL_SKY -} BablClassType; - - -typedef union _Babl Babl; -typedef struct _BablList BablList; - -/* common header for any item inserted into database */ -typedef struct -{ - BablClassType class_type; - int id; /*< a numerical id, look at 'babl-ids.h' for the reserved - ones */ - void *creator; - char *name; /*< the name this type exists under */ -} BablInstance; - - -typedef struct -BablConversion { - BablInstance instance; - const Babl *source; - const Babl *destination; - long cost; - double error; - union - { - BablFuncLinear linear; - BablFuncPlane plane; - BablFuncPlanar planar; - } function; - int processings; - long pixels; -} BablConversion; - - -typedef struct -{ - BablInstance instance; - BablList *from_list; - int bits; /*< number of bits used to represent the data type - (initially restricted to a multiple of 8) */ - double min_val; - double max_val; -} BablType; - -typedef struct -{ - BablType type; - int is_signed; - long max; - long min; -} BablTypeInteger; - -typedef struct -{ - BablType type; - /* sign - * biased_exponent - * mantissa */ -} BablTypeFloat; - - -typedef struct -{ - BablInstance instance; - BablList *from_list; - int horizontal; - int vertical; - char name[4]; -} BablSampling; - -typedef struct -{ - BablInstance instance; - int luma; - int chroma; - int alpha; -} BablComponent; - - -typedef struct -{ - BablInstance instance; - BablList *from_list; - int components; - BablComponent **component; - BablType **type; /*< must be doubles, used here for convenience in code */ -} BablModel; - -typedef struct -{ - BablInstance instance; - BablList *from_list; - int components; - BablComponent **component; - BablType **type; - void *image_template; /* image template for use with - linear (non-planer) images */ - - BablSampling **sampling; - BablModel *model; - int bytes_per_pixel; - int planar; - double loss; /*< average relative error when converting - from and to RGBA double */ - int visited; /* for convenience in code while searching - for conversion paths */ -} BablFormat; - -typedef struct -{ - BablInstance instance; - BablFormat *format; /*< (if known) */ - BablModel *model; /*< (always known) */ - int components; - BablComponent **component; - BablType **type; - BablSampling **sampling; - char **data; - int *pitch; - int *stride; -} BablImage; - -/* BablFish, common base class for various fishes. - */ -typedef struct -{ - BablInstance instance; - const Babl *source; - const Babl *destination; - - double error; /* the amount of noise introduced by the fish */ - - /* instrumentation */ - int processings; /* number of times the fish has been used */ - long pixels; /* number of pixels translates */ - long usecs; /* usecs spent within this fish */ -} BablFish; - - - -/* BablFishSimple is the simplest type of fish, wrapping a single - * conversion function, (note this might not be the optimal chosen - * conversion even if it exists) - * - * TODO: exterminate - */ -typedef struct -{ - BablFish fish; - BablConversion *conversion; -} BablFishSimple; - -#ifndef BABL_HARD_MAX_PATH_LENGTH -#define BABL_HARD_MAX_PATH_LENGTH 16 -#endif - -/* BablFishPath is a combination of registered conversions, both - * from the reference types / model conversions, and optimized format to - * format conversion. - * - * This is the most advanced scheduled species of fish, some future - * version of babl might even be evovling path fishes in a background - * thread, based on the fish instrumentation. For this to work in a future - * version transmogrification between the fish classes would be used. - */ -typedef struct -{ - BablFish fish; - double cost; /* number of ticks *10 + chain_length */ - double loss; /* error introduced */ - BablList *conversion_list; -} BablFishPath; - -/* BablFishReference - * - * A BablFishReference is not intended to be fast, thus the algorithm - * encoded can use a multi stage approach, based on the knowledge babl - * has encoded in the pixel formats. - * - * One of the contributions that would be welcome are new fish factories. - * - * TODO: - * * make optimal use of a single allocation containing enough space - * for the maximum amount of memory needed in two adjecant buffers - * at any time. - */ -typedef struct -{ - BablFish fish; -} BablFishReference; - -typedef struct -{ - BablInstance instance; /* path to .so / .dll is stored in instance name */ - void *dl_handle; - void (*destroy) (void); -} BablExtension; - -typedef union _Babl -{ - BablClassType class_type; - BablInstance instance; - BablType type; - BablSampling sampling; - BablComponent component; - BablModel model; - BablFormat format; - BablConversion conversion; - BablImage image; - BablFish fish; - BablFishReference fish_reference; - BablFishSimple fish_simple; - BablFishPath fish_path; - BablExtension extension; -} _Babl; - -#endif - diff --git a/babl/babl-component.c b/babl/babl-component.c index 8e873f7..4c84bba 100644 --- a/babl/babl-component.c +++ b/babl/babl-component.c @@ -127,4 +127,4 @@ babl_component_new (void *first_arg, return babl; } -BABL_CLASS_TEMPLATE (component) +BABL_CLASS (component) diff --git a/babl/babl-conversion.c b/babl/babl-conversion.c index d4dc114..7c028b5 100644 --- a/babl/babl-conversion.c +++ b/babl/babl-conversion.c @@ -555,4 +555,4 @@ babl_conversion_error (BablConversion *conversion) return error; } -BABL_CLASS_TEMPLATE (conversion) +BABL_CLASS (conversion) diff --git a/babl/babl-db.h b/babl/babl-db.h index d8c47c9..7aa4f37 100644 --- a/babl/babl-db.h +++ b/babl/babl-db.h @@ -19,8 +19,8 @@ #ifndef _DB_H #define _DB_H -#ifndef _BABL_CLASSES_H -#error babl-db.h is only to be included after babl-classes.h +#ifndef _BABL_H +#error babl-db.h is only to be included after babl.h #endif #include "babl-list.h" diff --git a/babl/babl-extension.c b/babl/babl-extension.c index 9219fad..921f7f4 100644 --- a/babl/babl-extension.c +++ b/babl/babl-extension.c @@ -357,4 +357,4 @@ each_babl_extension_destroy (Babl *babl, return 0; /* continue iterating */ } -BABL_CLASS_TEMPLATE (extension) +BABL_CLASS (extension) diff --git a/babl/babl-fish.c b/babl/babl-fish.c index db24fc0..8d7c37e 100644 --- a/babl/babl-fish.c +++ b/babl/babl-fish.c @@ -20,6 +20,7 @@ #include #include + typedef struct _BablFindFish BablFindFish; typedef struct _BablFindFish @@ -152,8 +153,7 @@ babl_fish_db (void) Babl * babl_fish (const void *source, - const void *destination, - ...) + const void *destination) { const Babl *source_format = NULL; const Babl *destination_format = NULL; @@ -323,6 +323,8 @@ babl_fish_process (Babl *babl, return ret; } + + static int each_babl_fish_destroy (Babl *babl, void *data) @@ -333,6 +335,4 @@ each_babl_fish_destroy (Babl *babl, return 0; /* continue iterating */ } -BABL_DEFINE_INIT (fish) -BABL_DEFINE_DESTROY (fish) -BABL_DEFINE_EACH (fish) +BABL_CLASS_MINIMAL (fish); diff --git a/babl/babl-format.c b/babl/babl-format.c index b4d65a0..827a079 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -435,4 +435,4 @@ babl_format_loss (Babl *babl) return loss; } -BABL_CLASS_TEMPLATE (format) +BABL_CLASS (format) diff --git a/babl/babl-hash-table.h b/babl/babl-hash-table.h index e4163bd..ae296fb 100644 --- a/babl/babl-hash-table.h +++ b/babl/babl-hash-table.h @@ -19,8 +19,8 @@ #ifndef _BABL_HASH_TABLE_H #define _BABL_HASH_TABLE_H -#ifndef _BABL_CLASSES_H -#error babl-hash-table.h is only to be included after babl-classes.h +#ifndef _BABL_H +#error babl-hash-table.h is only to be included after babl.h #endif diff --git a/babl/babl-internal.h b/babl/babl-internal.h index ef523aa..6d20b2b 100644 --- a/babl/babl-internal.h +++ b/babl/babl-internal.h @@ -32,8 +32,6 @@ #include #include "assert.h" - -#include "babl-classes.h" #undef _BABL_INTERNAL_H #include "babl.h" #define _BABL_INTERNAL_H @@ -177,49 +175,10 @@ while(0) extern int babl_hmpf_on_name_lookups; -const char *babl_class_name (BablClassType klass); +const char *babl_class_name (BablClassType klass); void babl_internal_init (void); void babl_internal_destroy (void); -#define BABL_DEFINE_EACH(type_name) \ -void \ -babl_##type_name##_each (BablEachFunction each_fun, \ - void *user_data) \ -{ \ - babl_db_each (db, each_fun, user_data); \ -} \ - -#define BABL_DEFINE_LOOKUP_BY_ID(type_name) \ -Babl * \ -babl_##type_name##_id (int id) \ -{ \ - Babl *babl; \ - babl = babl_db_exist_by_id (db, id); \ - if (!babl) \ - { \ - babl_fatal ("%s(%i): not found", __func__, id); \ - } \ - return babl; \ -} - -#define BABL_DEFINE_LOOKUP_BY_NAME(type_name) \ -Babl * \ -babl_##type_name (const char *name) \ -{ \ - Babl *babl; \ - \ - if (babl_hmpf_on_name_lookups) \ - { \ - babl_log ("%s(\"%s\"): hmpf!", __func__, name); \ - } \ - babl = babl_db_exist_by_name (db, name); \ - \ - if (!babl) \ - { \ - babl_fatal ("%s(\"%s\"): not found", __func__, name); \ - } \ - return babl; \ -} #ifndef BABL_INIT_HOOK #define BABL_INIT_HOOK @@ -234,34 +193,70 @@ babl_##type_name (const char *name) \ #define BABL_DESTROY_PRE_HOOK #endif -#define BABL_DEFINE_INIT(type_name) \ - \ - \ +/* this template is expanded in the files including babl-internal.h, + * generating code, the declarations for these functions are found in + * the BABL_CLASS expansions done in babl.h as well, thus babl.h needs + * to be kept in sync with the C files. + */ + +#define BABL_CLASS_MINIMAL(klass) \ void \ -babl_##type_name##_init (void) \ +babl_##klass##_init (void) \ { \ BABL_PRE_INIT_HOOK; \ if (!db) \ db=babl_db_init (); \ BABL_INIT_HOOK; \ -} - -#define BABL_DEFINE_DESTROY(type_name) \ +} \ + \ void \ -babl_##type_name##_destroy (void) \ +babl_##klass##_destroy (void) \ { \ BABL_DESTROY_PRE_HOOK; \ - babl_db_each (db,each_babl_##type_name##_destroy, NULL); \ + babl_db_each (db,each_babl_##klass##_destroy, NULL); \ babl_db_destroy (db); \ BABL_DESTROY_HOOK; \ -} +} \ + \ +void \ +babl_##klass##_each (BablEachFunction each_fun, \ + void *user_data) \ +{ \ + babl_db_each (db, each_fun, user_data); \ +} \ -#define BABL_CLASS_TEMPLATE(type_name) \ -BABL_DEFINE_INIT (type_name) \ -BABL_DEFINE_DESTROY (type_name) \ -BABL_DEFINE_LOOKUP_BY_NAME (type_name) \ -BABL_DEFINE_EACH (type_name) \ -BABL_DEFINE_LOOKUP_BY_ID (type_name) +#define BABL_CLASS(klass) \ +BABL_CLASS_MINIMAL(klass) \ + \ +Babl * \ +babl_##klass (const char *name) \ +{ \ + Babl *babl; \ + \ + if (babl_hmpf_on_name_lookups) \ + { \ + babl_log ("%s(\"%s\"): hmpf!", __func__, name); \ + } \ + babl = babl_db_exist_by_name (db, name); \ + \ + if (!babl) \ + { \ + babl_fatal ("%s(\"%s\"): not found", __func__, name); \ + } \ + return babl; \ +} \ + \ +Babl * \ +babl_##klass##_id (int id) \ +{ \ + Babl *babl; \ + babl = babl_db_exist_by_id (db, id); \ + if (!babl) \ + { \ + babl_fatal ("%s(%i): not found", __func__, id); \ + } \ + return babl; \ +} #define BABL(obj) ((Babl*)(obj)) diff --git a/babl/babl-list.h b/babl/babl-list.h index 139aee7..7b35dea 100644 --- a/babl/babl-list.h +++ b/babl/babl-list.h @@ -19,11 +19,11 @@ #ifndef _BABL_LIST_H #define _BABL_LIST_H -#ifndef _BABL_CLASSES_H -/* babl-classes.h contains forward declaration +#ifndef _BABL_H +/* babl.h contains forward declaration * typedef struct _BablList BablList; */ -#error babl-list.h is only to be included after babl-classes.h +#error babl-list.h is only to be included after babl.h #endif diff --git a/babl/babl-model.c b/babl/babl-model.c index db24723..5fd4908 100644 --- a/babl/babl-model.c +++ b/babl/babl-model.c @@ -327,4 +327,4 @@ babl_model_is_symmetric (Babl *babl) return symmetric; } -BABL_CLASS_TEMPLATE (model) +BABL_CLASS (model) diff --git a/babl/babl-type.c b/babl/babl-type.c index d025ca3..399d831 100644 --- a/babl/babl-type.c +++ b/babl/babl-type.c @@ -252,4 +252,4 @@ babl_type_is_symmetric (Babl *babl) return is_symmetrical; } -BABL_CLASS_TEMPLATE (type) +BABL_CLASS (type) diff --git a/babl/babl.h b/babl/babl.h index 5c31627..b085cb4 100644 --- a/babl/babl.h +++ b/babl/babl.h @@ -24,14 +24,54 @@ #ifndef _BABL_H #define _BABL_H -#include "babl-classes.h" +#include + #ifdef _BABL_INTERNAL_H #error babl.h included after babl-internal.h #endif -#ifndef _BABL_CLASSES_H -#define Babl void + +typedef union _Babl Babl; +/* Union used for quick convenient access to any field of any BablInstance */ + +typedef struct _BablList BablList; + +#ifndef BABL_HARD_MAX_PATH_LENGTH +#define BABL_HARD_MAX_PATH_LENGTH 16 #endif +/* magic number used at the start of all babl objects, used to do + * differentiation in polymorphic functions. (as well as manual + * type check assertions). + */ +#define BABL_MAGIC 0xbAb100 + +enum { + BABL_INSTANCE = BABL_MAGIC, + BABL_TYPE, + BABL_TYPE_INTEGER, + BABL_TYPE_FLOAT, + BABL_SAMPLING, + BABL_COMPONENT, + BABL_MODEL, + BABL_FORMAT, + + BABL_CONVERSION, + BABL_CONVERSION_LINEAR, + BABL_CONVERSION_PLANE, + BABL_CONVERSION_PLANAR, + + BABL_FISH, + BABL_FISH_REFERENCE, + BABL_FISH_SIMPLE, + BABL_FISH_PATH, + BABL_IMAGE, + + BABL_EXTENSION, + + BABL_SKY +}; +typedef unsigned int BablClassType; + /** Initialize the babl library */ void babl_init (void); @@ -47,70 +87,62 @@ void babl_destroy (void); #define BABL_ARG_NULL_TERMINATED #endif -#define BABL_CLASS_NO_NAME(type_name) \ - \ -void babl_##type_name##_init (void); \ -void babl_##type_name##_destroy (void); \ -Babl * babl_##type_name##_id (int id); \ -void babl_##type_name##_each (BablEachFunction each_fun, \ - void *user_data); - -#define BABL_CLASS(type_name) \ - \ -BABL_CLASS_NO_NAME (type_name) \ -Babl * babl_##type_name (const char *name); \ -Babl * babl_##type_name##_new (void *first_arg, \ - ...) BABL_ARG_NULL_TERMINATED; - typedef int (*BablEachFunction) (Babl *entry, void *data); +/* All Classes in babl have common functionality like the ability + * to be iterated over, common functionality is defined through these + * macros. + */ +#define BABL_CLASS(klass) \ + \ +void babl_##klass##_init (void); \ +void babl_##klass##_destroy (void); \ +Babl * babl_##klass##_id (int id); \ +void babl_##klass##_each (BablEachFunction each_fun, \ + void *user_data) -/****************************************************************/ -/* BablFish */ BABL_CLASS_NO_NAME (fish) -/* Create a babl fish capable of converting from source_format to - * destination_format, source and destination can be - * either strings with the names of the formats or BablFormat objects. +/* creates a class that has a specific name connected to it, that + * also allows defining a new instance. These classes share common + * functionality with the non_name classes but have two extra methods, + * the means to lookup by name, as well as to create new named objects + * that later can be looked up. */ -Babl * babl_fish (const void *source_format, - const void *destination_format, - ...); +#define BABL_NAMED_CLASS(klass) \ + \ +BABL_CLASS (klass); \ +Babl * babl_##klass (const char *name); \ +Babl * babl_##klass##_new (void *first_arg, \ + ...) BABL_ARG_NULL_TERMINATED -/** Process n pixels from source to destination using babl_fish, - * returns number of pixels converted. + + +/* common header for any item inserted into database, the actual + * implementation of babl-instance is in babl-internal */ -long babl_process (Babl *babl_fish, - void *source, - void *destination, - long n); +typedef struct +{ + BablClassType class_type; + int id; /*< a numerical id, look at 'babl-ids.h' for the reserved + ones */ + void *creator; + char *name; /*< the name this type exists under */ +} BablInstance; -/****************************************************************/ -/* BablImage */ BABL_CLASS_NO_NAME (image) -/* - * Babl images can be used for planar buffers instead of linear buffers for - * babl_process(), BablImages are still experimental, for now BablImages can be - * passed to babl_process, two different babl_process() functions will be - * needed for this since the polymorphism cannot be trusted to work on linear - * buffers. +/** + * babl_name: * - * Babl * babl_image (BablComponent *component1, - * void *data, - * int pitch, - * int stride, - * [BablComponent *component1, - * void *data, - * int pitch, - * int stride, - * ...] - * NULL); + * Return a string decsribing a BablInstance, might work better than + * babl->instance.name when a good human readable name is desired. + * + * Returns: a name describing the instance. */ -Babl * babl_image (void *first_component, - ...) BABL_ARG_NULL_TERMINATED; - - +const char *babl_name (const Babl *babl); +void babl_introspect (Babl *babl); /* introspect a given BablObject */ /****************************************************************/ -/* BablType */ BABL_CLASS (type) +/* BablType */ +BABL_NAMED_CLASS (type); /* * A data type that babl can have in it's buffers, requires * conversions to and from "double" to be registered before @@ -122,18 +154,85 @@ Babl * babl_image (void *first_component, * ["max_val", double max_val,] * NULL); */ +Babl *babl_type_id (int id); +void babl_type_each (BablEachFunction each_fun, + void *user_data); +Babl * babl_type (const char *name); +Babl * babl_type_new (void *first_arg, + ...) BABL_ARG_NULL_TERMINATED; + +typedef struct +{ + BablInstance instance; + BablList *from_list; + int bits; /*< number of bits used to represent the data type + (initially restricted to a multiple of 8) */ + double min_val; + double max_val; +} BablType; + +typedef struct +{ + BablType type; + int is_signed; + long max; + long min; +} BablTypeInteger; + +typedef struct +{ + BablType type; + /* sign + * biased_exponent + * mantissa */ +} BablTypeFloat; + + +/****************************************************************/ +/* BablSampling */ +BABL_CLASS (sampling); +/**/ +Babl * babl_sampling (int horizontal, + int vertical); +Babl *babl_sampling_id (int id); +void babl_sampling_each (BablEachFunction each_fun, + void *user_data); +typedef struct +{ + BablInstance instance; + BablList *from_list; + int horizontal; + int vertical; + char name[4]; +} BablSampling; /****************************************************************/ -/* BablComponent */ BABL_CLASS (component) +/* BablComponent */ +BABL_NAMED_CLASS (component); /* * Babl * babl_component_new (const char *name, * NULL); */ +Babl *babl_component_id (int id); +void babl_component_each (BablEachFunction each_fun, + void *user_data); +Babl * babl_component (const char *name); +Babl * babl_component_new (void *first_arg, + ...) BABL_ARG_NULL_TERMINATED; + +typedef struct +{ + BablInstance instance; + int luma; + int chroma; + int alpha; +} BablComponent; /****************************************************************/ -/* BablModel */ BABL_CLASS (model) +/* BablModel */ +BABL_NAMED_CLASS (model); /* * Babl * babl_model_new (["name", const char *name,] * BablComponent *component1, @@ -144,15 +243,26 @@ Babl * babl_image (void *first_component, * name of all the involved components. * */ +Babl *babl_model_id (int id); +void babl_model_each (BablEachFunction each_fun, + void *user_data); +Babl * babl_model (const char *name); +Babl * babl_model_new (void *first_arg, + ...) BABL_ARG_NULL_TERMINATED; + +typedef struct +{ + BablInstance instance; + BablList *from_list; + int components; + BablComponent **component; + BablType **type; /*< must be doubles, used here for convenience in code */ +} BablModel; -/****************************************************************/ -/* BablSampling */ BABL_CLASS_NO_NAME (sampling) -/**/ -Babl * babl_sampling (int horizontal, - int vertical); /****************************************************************/ -/* BablFormat */ BABL_CLASS (format) +/* BablFormat */ +BABL_NAMED_CLASS (format); /* * Babl * babl_format_new (["name", const char *name,] * BablModel *model, @@ -170,16 +280,78 @@ Babl * babl_sampling (int horizontal, * components as well. If no name is provided a (long) descriptive * name is used. */ +Babl *babl_format_id (int id); +void babl_format_each (BablEachFunction each_fun, + void *user_data); +Babl * babl_format (const char *name); +Babl * babl_format_new (void *first_arg, + ...) BABL_ARG_NULL_TERMINATED; + +typedef struct +{ + BablInstance instance; + BablList *from_list; + int components; + BablComponent **component; + BablType **type; + void *image_template; /* image template for use with + linear (non-planer) images */ + + BablSampling **sampling; + BablModel *model; + int bytes_per_pixel; + int planar; + double loss; /*< average relative error when converting + from and to RGBA double */ + int visited; /* for convenience in code while searching + for conversion paths */ +} BablFormat; /****************************************************************/ -/* BablExtension */ BABL_CLASS (extension) +/* BablImage */ +BABL_CLASS (image); /* - * BablExtension objects are only used internally in babl. + * Babl images can be used for planar buffers instead of linear buffers for + * babl_process(), BablImages are still experimental, for now BablImages can be + * passed to babl_process, two different babl_process() functions will be + * needed for this since the polymorphism cannot be trusted to work on linear + * buffers that originate outside babl's control. + * + * Babl * babl_image (BablComponent *component1, + * void *data, + * int pitch, + * int stride, + * [BablComponent *component1, + * void *data, + * int pitch, + * int stride, + * ...] + * NULL); */ +Babl * babl_image (void *first_component, + ...) BABL_ARG_NULL_TERMINATED; +Babl *babl_image_id (int id); +void babl_image_each (BablEachFunction each_fun, + void *user_data); +typedef struct +{ + BablInstance instance; + BablFormat *format; /*< (if known) */ + BablModel *model; /*< (always known) */ + int components; + BablComponent **component; + BablType **type; + BablSampling **sampling; + char **data; + int *pitch; + int *stride; +} BablImage; + /****************************************************************/ -/* BablConversion */ BABL_CLASS (conversion) +/* BablConversion */ +BABL_NAMED_CLASS (conversion); /* * Babl * babl_conversion_new (, BablConversionFunc conv_func, * NULL); */ +Babl *babl_conversion_id (int id); +void babl_conversion_each (BablEachFunction each_fun, + void *user_data); +Babl * babl_conversion (const char *name); +Babl * babl_conversion_new (void *first_arg, + ...) BABL_ARG_NULL_TERMINATED; +/* Type and Format */ +typedef long (*BablFuncLinear) (char *src, + char *dst, + long n); -const char *babl_name (const Babl *babl); /* returns the name of a babl object */ -void babl_introspect (Babl *babl); /* introspect a given BablObject */ +/* Signature of functions registered for reference type + * conversions, + */ +typedef long (*BablFuncPlane) (char *src, + char *dst, + int src_pitch, + int dst_pitch, + long n); + +/* TypePlanar,ModelPlanar and FormatPlanar */ +typedef long (*BablFuncPlanar) (int src_bands, + char *src[], + int src_pitch[], + int dst_bands, + char *dst[], + int dst_pitch[], + long n); + +typedef struct +BablConversion { + BablInstance instance; + const Babl *source; + const Babl *destination; + long cost; + double error; + union + { + BablFuncLinear linear; + BablFuncPlane plane; + BablFuncPlanar planar; + } function; + int processings; + long pixels; +} BablConversion; + + +/****************************************************************/ +/* BablFish */ +BABL_CLASS (fish); +/* Create a babl fish capable of converting from source_format to + * destination_format, source and destination can be + * either strings with the names of the formats or BablFormat objects. + */ +Babl * babl_fish (const void *source_format, + const void *destination_format); + +/** Process n pixels from source to destination using babl_fish, + * returns number of pixels converted. + */ +long babl_process (Babl *babl_fish, + void *source, + void *destination, + long n); + +Babl *babl_fish_id (int id); +void babl_fish_each (BablEachFunction each_fun, + void *user_data); + +/* BablFish, common base class for various fishes. + */ +typedef struct +{ + BablInstance instance; + const Babl *source; + const Babl *destination; + + double error; /* the amount of noise introduced by the fish */ + + /* instrumentation */ + int processings; /* number of times the fish has been used */ + long pixels; /* number of pixels translates */ + long usecs; /* usecs spent within this fish */ +} BablFish; + +/* BablFishSimple is the simplest type of fish, wrapping a single + * conversion function, (note this might not be the optimal chosen + * conversion even if it exists) + * + * TODO: exterminate + */ +typedef struct +{ + BablFish fish; + BablConversion *conversion; +} BablFishSimple; + + +/* BablFishPath is a combination of registered conversions, both + * from the reference types / model conversions, and optimized format to + * format conversion. + * + * This is the most advanced scheduled species of fish, some future + * version of babl might even be evovling path fishes in a background + * thread, based on the fish instrumentation. For this to work in a future + * version transmogrification between the fish classes would be used. + */ +typedef struct +{ + BablFish fish; + double cost; /* number of ticks *10 + chain_length */ + double loss; /* error introduced */ + BablList *conversion_list; +} BablFishPath; + +/* BablFishReference + * + * A BablFishReference is not intended to be fast, thus the algorithm + * encoded can use a multi stage approach, based on the knowledge babl + * has encoded in the pixel formats. + * + * One of the contributions that would be welcome are new fish factories. + * + * TODO: + * * make optimal use of a single allocation containing enough space + * for the maximum amount of memory needed in two adjecant buffers + * at any time. + */ +typedef struct +{ + BablFish fish; +} BablFishReference; + + +/****************************************************************/ +/* BablExtension */ +BABL_NAMED_CLASS (extension); +/* + * BablExtension objects are only used internally in babl. + */ +Babl *babl_extension_id (int id); +void babl_extension_each (BablEachFunction each_fun, + void *user_data); +Babl * babl_extension (const char *name); +Babl * babl_extension_new (void *first_arg, + ...) BABL_ARG_NULL_TERMINATED; + +typedef struct +{ + BablInstance instance; /* path to .so / .dll is stored in instance name */ + void *dl_handle; + void (*destroy) (void); +} BablExtension; + + + +/* This union can be used for convenient access to any field without the need + * to case if the variable already is of the type Babl * + */ +typedef union _Babl +{ + BablClassType class_type; + BablInstance instance; + BablType type; + BablSampling sampling; + BablComponent component; + BablModel model; + BablFormat format; + BablConversion conversion; + BablImage image; + BablFish fish; + BablFishReference fish_reference; + BablFishSimple fish_simple; + BablFishPath fish_path; + BablExtension extension; +} _Babl; #undef BABL_CLASS -#include +#undef BABL_NAMED_CLASS #endif -- 2.30.2